package com.lm.service.impl;

import com.lm.mapper.MenuMapper;
import com.lm.pojo.Menu;
import com.lm.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @version 1.0
 * @dscription:TODO
 * @author32477
 * @date 2025/9/26 15:49
 */
@Service
public class MenuServiceImpl implements MenuService {

    @Autowired
    MenuMapper menuMapper;

    @Override
    public List<Menu> getList(Integer roleId) {
        int parentId = 0;
        List<Menu> list = getMenuNode(parentId,roleId);
        return list;
    }

    private List<Menu> getMenuNode(int parentId,Integer roleId) {
        List<Menu> menuList = menuMapper.getMenuByParentIdAndRoleId(parentId, roleId);
        for (Menu menu : menuList) {
            menu.setChildren(getMenuNode(menu.getMenuId(), roleId));
        }
        return menuList;
    }
}
